# {{{ Unbind first
unbind-key C-b #no more C^b
unbind-key [
# }}}

# {{{ Options
set-option -g base-index 1
set-window-option -g pane-base-index 1
set-option -g default-terminal "screen-256color"
# -- vi mode
set-window-option -g mode-keys vi
set-option -g status-keys vi
set-option -g status-keys vi
set-option -g repeat-time 1000
set-option -sg escape-time 0
set-option -g history-limit 4096
# }}}

# {{{ prefix
# Semicolon is the only key that isn't bound by readline
# this creates a problem inside of ttys...
set-option -g prefix C-f
bind-key f send-prefix
# }}}

# Key bindings {{{
bind-key S source-file ~/.tmux.conf \; display-message "source-file done"

# All sorts of Vi-type bindings
# https://github.com/justone/dotfiles/blob/personal/.tmux.shared#L3
# VI for switching between
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R

# keybindings to make resizing easier
bind-key -r C-h resize-pane -L
bind-key -r C-j resize-pane -D
bind-key -r C-k resize-pane -U
bind-key -r C-l resize-pane -R
bind-key | resize-pane -Z \; display-message "Zoom zoom zoom"

# Pane movement
bind-key J command-prompt -p "join pane from:"  "join-pane -s '%%'"
bind-key B command-prompt -p "break pane to:"  "break-pane -t '%%'"
bind-key M-k move-pane -t ':+'
bind-key M-j move-pane -t ':-'

# Vi copy and paste in tmux
# http://joncairns.com/2013/06/copying-between-tmux-buffers-and-the-system-clipboard/
bind-key Escape copy-mode

# bind-key -T vi-mode-copy 'v' send -X begin-selection
# bind-key -T vi-mode-copy 'y' send -X copy-selection
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection
# }}}

# System Specific {{{
if-shell 'test "$(uname -s)" = "Darwin"' 'bind-key y run-shell "tmux show-buffer | pbcopy" \; display-message "Copied tmux buffer to system clipboard"'
if-shell 'test "$(uname -s)" = "Linux"' 'bind-key y run-shell "tmux show-buffer | xsel -pi" \; display-message "Copied tmux buffer to system clipboard"'

# only if this is the first level of inception do that fancy status bar
if-shell '[ -z "$SSH_CONNECTION" ]' 'source "$HOME/.tmux-local.conf"' 'source "$HOME/.tmux-inception.conf"'

#dumb osx
if-shell 'test "$(uname)" = "Darwin"' 'source "$HOME/.tmux-osx.conf"'
# }}}
